package com.christian.thread.daemon;

/**
 * 文件描述：守护线程
 *
 * @Author：wang
 * @Date：2020-01-11 22:19:38
 */
public class DaemonThread {

    public static void main(String[] args) {

        //创建线程
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(3 * 100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("我是子线程。。。");
        });

        //设置守护线程
        t1.setDaemon(true);

        //启动线程
        t1.start();

        System.out.println("子线程当前状态：" + t1.getState());

        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(3 * 100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("我是主线程。。。");
        }

        System.out.println("主线程执行完毕！！！");


        System.out.println("子线程当前状态：" + t1.getState());
    }
}
